﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.DL.Project;

public partial class sysadmin_UserInfo_EditorPassword : PowerCreator.LMS.Web.Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            this.btnSave.Attributes.Add("OnClick", "return checkForm()");
            
        }

    }

    protected override void InitPage()
    {
        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        int uid = GetLoginEntity.UserID;

        if (GetLoginEntity.Password != MD5Helper.GetMD5(txt_old_PassWord.Text.Trim()))
        {
            lbl_msg_Error.Text = GetLanageValueByKey("EditPWD_msg_g1", PowerCreator.LMS.Language.LanagetItemType.Page);
            return;
        }
        else
        {
            if (string.IsNullOrEmpty(txt_new_PassWord.Text.Trim()))
            {
                lbl_msg_Error.Text = GetLanageValueByKey("EditPWD_msg_g2", PowerCreator.LMS.Language.LanagetItemType.Page);
                return;
            }
            if (txt_new_PassWord.Text.Trim().Length < 6 || txt_new_PassWord.Text.Trim().Length > 20)
            {
                lbl_msg_Error.Text = GetLanageValueByKey("EditPWD_msg_g3", PowerCreator.LMS.Language.LanagetItemType.Page);
                return;
            }

            if (!txt_new_PassWord.Text.Trim().Equals(txt_db_PassWord.Text.Trim()))
            {
                lbl_msg_Error.Text = GetLanageValueByKey("EditPWD_msg_g4", PowerCreator.LMS.Language.LanagetItemType.Page);
                return;
            }


            TOAdvancedUser obj = new TOAdvancedUser();
            VOTOAdvancedUser vo = new VOTOAdvancedUser();
            vo = obj.Load(uid);
            string newPassword = MD5Helper.GetMD5(txt_new_PassWord.Text.Trim());
            vo.AUserPwd = newPassword;

            if (obj.Update(vo))
            {
                GetLoginEntity.Password = newPassword;
                GetLoginEntity.VOAdvancedUser.AUserPwd = newPassword;
                string url = "EditUser.aspx";
                Script.RedirectURL(url);
            }
            else
            {
                lbl_msg_Error.Text="修改用户密码失败!";
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "EditUser.aspx";
        Script.RedirectURL(url);
    }
}
